export default {
    data() {
        return {
            paginationModel: {
                current: 1,
                size: 30,
                total: 100
            },
            sortModel: {
                asc: '',
                desc: ''
            }
        }
    },
    methods: {
        /**
         * 设置表格高度自适应
         * @param tableRef
         * @param bottomOffset
         */
        setTableHeightAdaptiveHandler(tableRef, bottomOffset = 56) {
            if (!tableRef) {
                throw new Error('tableRef is required')
            }
            this.$nextTick(() => {
                const {componentInstance: $table} = tableRef.$vnode
                const height = window.innerHeight - tableRef.$el.getBoundingClientRect().top - bottomOffset
                $table.layout.setHeight(height)
                $table.doLayout()
            })
        },
        /**
         * 设置分页数据模型
         * @param paginationModel
         */
        setPaginationModelHandler(paginationModel) {
            this.paginationModel.total = paginationModel.total
            this.paginationModel.current = paginationModel.current
            this.paginationModel.size = paginationModel.size
        },
        /**
         * 获取分页数据模型
         */
        getPaginationModelHandler() {
            return {
                current: this.paginationModel.current,
                size: this.paginationModel.size
            }
        },
        /**
         * 重置排序数据模型
         */
        resetSortModelHandler() {
            this.sortModel.asc = ''
            this.sortModel.desc = ''
        }
    }
}
